home *** CD-ROM | disk | FTP | other *** search
- head 1.2;
- branch ;
- access ;
- symbols ;
- locks ; strict;
- comment @ * @;
-
-
- 1.2
- date 92.06.04.17.11.03; author jhh; state Exp;
- branches ;
- next 1.1;
-
- 1.1
- date 88.10.27.16.03.08; author ouster; state Exp;
- branches ;
- next ;
-
-
- desc
- @@
-
-
- 1.2
- log
- @changed to use tk library
- @
- text
- @/*
- * select.c --
- *
- * This is a simple program that outputs the Sx selection on
- * its standard output.
- *
- * Copyright 1987 Regents of the University of California
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies. The University of California
- * makes no representations about the suitability of this
- * software for any purpose. It is provided "as is" without
- * express or implied warranty.
- */
-
- #ifndef lint
- static char rcsid[] = "$Header: /a/newcmds/select/RCS/select.c,v 1.1 88/10/27 16:03:08 ouster Exp $ SPRITE (Berkeley)";
- #endif not lint
-
- #include <stdio.h>
- #include <tk.h>
- #include <tcl.h>
- #include <X11/Xatom.h>
-
- typedef struct {
- char *string; /* Contents of selection are
- * here. This space is malloc-ed. */
- int bytesAvl; /* Total number of bytes available
- * at string. */
- int bytesUsed; /* Bytes currently in use in string,
- * not including the terminating
- * NULL. */
- } GetInfo;
-
- static int SelGetProc _ARGS_((ClientData clientData, char *portion));
-
- main()
- {
- Tk_Window window;
- Tcl_Interp *interp;
- int rc;
- GetInfo getInfo;
-
- interp = Tcl_CreateInterp();
- if (interp == NULL) {
- fprintf(stderr, "Couldn't create TCL interpreter\n");
- exit(1);
- }
- window = Tk_CreateMainWindow(interp, NULL, "select");
- if (window == NULL) {
- fprintf(stderr, "%s\n", interp->result);
- exit(1);
- }
- Tk_MakeWindowExist(window);
- getInfo.string = (char *) ckalloc(100);
- getInfo.bytesAvl = 100;
- getInfo.bytesUsed = 0;
- rc = Tk_GetSelection(interp, window, XA_STRING, SelGetProc,
- (ClientData) &getInfo);
- if (rc != TCL_OK) {
- fprintf(stderr, "%s\n", interp->result);
- exit(1);
- }
- write(1, getInfo.string, getInfo.bytesUsed);
- exit(0);
- }
-
- /*
- *--------------------------------------------------------------
- *
- * SelGetProc --
- *
- * This procedure is invoked to process pieces of the
- * selection as they arrive during Tk_GetSelection.
- *
- * Results:
- * Always returns TCL_OK.
- *
- * Side effects:
- * Bytes are stored in getInfoPtr->string, which is
- * expanded if necessary.
- *
- *--------------------------------------------------------------
- */
-
- /* ARGSUSED */
- static int
- SelGetProc(clientData, interp, portion)
- ClientData clientData; /* Information about partially-
- * assembled result. */
- Tcl_Interp *interp; /* Interpreter used for error
- * reporting (not used). */
- char *portion; /* New information to be appended. */
- {
- register GetInfo *getInfoPtr = (GetInfo *) clientData;
- int newLength;
-
- newLength = strlen(portion) + getInfoPtr->bytesUsed;
-
- /*
- * Grow the result area if we've run out of space.
- */
-
- if (newLength >= getInfoPtr->bytesAvl) {
- char *newString;
-
- getInfoPtr->bytesAvl *= 2;
- if (getInfoPtr->bytesAvl <= newLength) {
- getInfoPtr->bytesAvl = newLength + 1;
- }
- newString = (char *) ckalloc((unsigned) getInfoPtr->bytesAvl);
- memcpy((char *) newString, (char *) getInfoPtr->string,
- getInfoPtr->bytesUsed);
- ckfree(getInfoPtr->string);
- getInfoPtr->string = newString;
- }
-
- /*
- * Append the new data to what was already there.
- */
-
- strcpy(getInfoPtr->string + getInfoPtr->bytesUsed, portion);
- getInfoPtr->bytesUsed = newLength;
- return TCL_OK;
- }
-
- @
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @d18 1
- a18 1
- static char rcsid[] = "$Header: select.c,v 1.2 88/01/07 09:15:41 ouster Exp $ SPRITE (Berkeley)";
- a20 1
- #include <X11/Xlib.h>
- d22 3
- a24 1
- #include <sx.h>
- d26 12
- d40 4
- a43 5
- #define BUFFER_SIZE 2000
- char buffer[BUFFER_SIZE];
- char format[SX_FORMAT_SIZE];
- int i, byteCount, dummy;
- Display *display;
- d45 18
- a62 4
- display = XOpenDisplay((char *) NULL);
- if (display == NULL) {
- fprintf(stderr, "Select: couldn't open display. Is your");
- fprintf(stderr, " DISPLAY environment variable set?\n");
- d64 47
- a110 11
- };
- Sx_SetErrorHandler();
- for (i = 0; ; i += BUFFER_SIZE) {
- byteCount = Sx_SelectionGet(display, "text", i, BUFFER_SIZE,
- buffer, format);
- if (byteCount == 0) {
- break;
- };
- write(1, (char *) buffer, byteCount);
- if (byteCount < BUFFER_SIZE) {
- break;
- d112 5
- d118 8
- a125 1
- exit(0);
- d127 1
- @
-